package com.tcs.netty.channel;

import com.tcs.netty.channel.handler.ServerChannelhandler;
import com.tcs.netty.code.decoder.MyObjDecoder;
import com.tcs.netty.code.encoder.MyObjEncoder;
import com.tcs.model.datastandardization.RequestStanBean;
import com.tcs.model.datastandardization.ResponseStanBean;
import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.handler.codec.DelimiterBasedFrameDecoder;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
import io.netty.handler.codec.LineBasedFrameDecoder;
import io.netty.handler.codec.protobuf.ProtobufVarint32FrameDecoder;
import io.netty.handler.codec.protobuf.ProtobufVarint32LengthFieldPrepender;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ChannelInit extends ChannelInitializer {

    private final Logger logger = LoggerFactory.getLogger(ChannelInit.class);

    @Override
    protected void initChannel(Channel ch) throws Exception {
        logger.debug("初始化通道参数");
        // 解码器
        ch.pipeline().addFirst(new LineBasedFrameDecoder(1024 * 1024));
        ch.pipeline().addLast(new MyObjDecoder(RequestStanBean.class));
        // 编码器
        ch.pipeline().addLast(new MyObjEncoder(ResponseStanBean.class));
        ch.pipeline().addLast("channelHandler", new ServerChannelhandler());
    }
}
